package firstping.controller;

import java.io.IOException;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import firstping.string.Utils;

@SuppressWarnings("serial")
public class SpotCheckServlet extends HttpServlet {
	public void doGet(HttpServletRequest req, HttpServletResponse resp)
			throws IOException {
		
		String title_url = Utils.fomatDomain(req.getParameter("name"));
		
		if((title_url != null && Utils.checkDomain(title_url)) || title_url == null)
		{
			req.setAttribute("title", "Spot check");
			req.setAttribute("description", "Spot check .firstping.com - We provide web site monitoring to webmasters. Monitor your web site is availability 24 hours a day, 7 days a week with instant email alerts and weekly web site performance statistics.");
			req.setAttribute("keyword", "account,monitoring domain,firstping,statistics site,add site,contact,faq,service,spot check");
			
			req.setAttribute("name", title_url);
			
			try {
				req.getRequestDispatcher("/spot_check.jsp").forward(req, resp);
			} catch (Exception e) {
				// TODO: handle exception
			}
		} else {
			req.setAttribute("error", "<h3 class=\"contact\"><strong class='alert_message'>Domain does not exist !</strong></h3>");
			req.setAttribute("title", "Spot check");
			req.setAttribute("description", "Spot check .firstping.com - We provide web site monitoring to webmasters. Monitor your web site is availability 24 hours a day, 7 days a week with instant email alerts and weekly web site performance statistics.");
			req.setAttribute("keyword", "account,monitoring domain,firstping,statistics site,add site,contact,faq,service,spot check");
			try {
				req.getRequestDispatcher("/spot_check.jsp").forward(req, resp);
			} catch (Exception e) {
				// TODO: handle exception
			}
			resp.getWriter().println("<a href='/'>Home page</a><br/><br/>Domain does not exist ! <br/><br/><a href='javascript:void(0)' onclick='history.go(-1)'>Back</a>");
		}
	}
}
